Add API key suspended message and format code in AuthWithApiMiddleware#1541
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds handling for suspended user accounts when authenticating with API keys and converts the auth-with-api.middleware.ts file to use tab indentation (consistent with the project's Biome formatter configuration).
Changes:
- Added
API_KEY_SUSPENDEDerror message constant - Added logic to check if a user account is suspended during API key authentication
- Reformatted auth-with-api.middleware.ts from 2-space to tab indentation
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| backend/src/exceptions/text/messages.ts | Added new API_KEY_SUSPENDED error message constant for suspended user accounts |
| backend/src/authorization/auth-with-api.middleware.ts | Added suspended user check in API key authentication flow and reformatted code to use tab indentation per biome.json config |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (foundUserByApiKey.suspended) { | ||
| throw new UnauthorizedException(Messages.API_KEY_SUSPENDED); | ||
| } | ||
|
|
||
| if (!foundUserByApiKey) { | ||
| throw new NotFoundException(Messages.NO_AUTH_KEYS_FOUND); | ||
| } |
There was a problem hiding this comment.
The null check for foundUserByApiKey must be performed before accessing its suspended property. Currently, if no user is found with the provided API key, the code will throw a runtime error when trying to access .suspended on a null object at line 107. The null check on lines 111-113 should be moved before the suspended check on lines 107-109.
| if (foundUserByApiKey.suspended) { | |
| throw new UnauthorizedException(Messages.API_KEY_SUSPENDED); | |
| } | |
| if (!foundUserByApiKey) { | |
| throw new NotFoundException(Messages.NO_AUTH_KEYS_FOUND); | |
| } | |
| if (!foundUserByApiKey) { | |
| throw new NotFoundException(Messages.NO_AUTH_KEYS_FOUND); | |
| } | |
| if (foundUserByApiKey.suspended) { | |
| throw new UnauthorizedException(Messages.API_KEY_SUSPENDED); | |
| } |
No description provided.